package com.learning.spring.cloud.ms.consumer.movie.feign;

import com.learning.spring.cloud.ms.consumer.movie.entity.User;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Map;

/**
 * ClassName: UserFeignService
 * Description: Feign 客户端实现声明式REST调用
 * 1- 注解 @FeignClient 中的ms-provider-user是一个任意客户端名称，用于创建Ribbon负载均衡（所以默认实现了负载）。因为Eureka的缘故，Ribbon会把ms-provider-user解析成ms-provider-user Server注册表中的服务
 * 2- 可以使用 url属性指定请求的URL地址
 * <p>
 * <p>
 * <p>
 * Date: 2019/6/4 14:59 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@FeignClient(name = "ms-provider-user")
public interface UserFeignService {

    /**
     * @param id
     * @return
     */
    @GetMapping(value = "/user/{id}")
    User findById(@PathVariable("id") Long id);


    /**
     * 该请求不会成功。虽然指定GET, 这种方法仍然会使用POST方法发送
     *
     * @param user
     * @return
     */
    @RequestMapping(value = "/user/get", method = RequestMethod.GET)
    User get(User user);

    /**
     * 通过参数请求
     *
     * @param id
     * @param username
     * @return
     */
    @GetMapping(value = "/user/get")
    User getByParam(@RequestParam("id") Long id, @RequestParam("username") String username);

    /**
     * 参数封装成Map请求
     *
     * @param map
     * @return
     */
    @GetMapping(value = "/user/get")
    User getByMap(@RequestParam Map<String, Object> map);

    /**
     * Post 请求
     *
     * @param user
     * @return
     */
    @PostMapping(value = "/user/post")
    User post(@RequestBody User user);
}
